package main

import (
	"fmt"
	"math/rand"
)

func randArray(num int, randLimit int) []int {
	var limit int
	var numArr []int
	for {
		randNum := rand.Intn(randLimit + 1)
		if randNum == 0 {
			continue
		}
		numArr = append(numArr, randNum)
		limit++
		if limit == num {
			break
		}
	}
	return numArr
}

func fibiNum(index int) (number int) {
	if index == 1 || index == 2 {
		number = 1
	} else {
		number = fibiNum(index-1) + fibiNum(index-2)
	}
	return number
}

func main() {
	fmt.Println("Q1:")
	for i := 1; i <= 9; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%d*%d=%d\t", j, i, i*j)
		}
		fmt.Println()
	}

	fmt.Println("Q2:")
	numArray := randArray(20, 20)
	fmt.Printf("len:%d list:%#v\n", len(numArray), numArray)

	var sum, multiplication int = 0, 1
	for _, item := range numArray {
		if item%2 == 0 {
			sum += item
		} else {
			multiplication *= item
		}
	}
	fmt.Printf("add sum:%d,mutiplation res:%d\n", sum, multiplication)

	var sum2, multiplication2 int = 0, 1
	for i := 0; i < len(numArray); i++ {
		num := numArray[i]
		if num&1 == 1 {
			multiplication2 *= num
		} else {
			sum2 += num
		}
	}
	fmt.Printf("add sum:%d,mutiplation res:%d\n", sum2, multiplication2)

	fmt.Println("Q3:") //1 1 2 3 5 ..
	var fbArray []int
	var i int = 1
	for {
		number := fibiNum(i)
		if number > 100 {
			break
		}
		fbArray = append(fbArray, number)
		i++
	}
	fmt.Println(fbArray)

}

// 阿飞老师的批改
// 1. 代码逻辑清晰，适当写一些注释，方便自己以后查看
